<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>密码找回</title>
		
	</head>
	<body>
		找回账号&nbsp;:&nbsp;<input type="text" name="" placeholder="请输入找回账号" id="username">&nbsp;&nbsp;<button onclick="getById()">点击申诉</button><br>
		验证码&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="" placeholder="手机收到的验证码" id="verify" onblur="checkVerifyCode()">&nbsp;&nbsp;<div style="display: inline" id="checkVerify"></div><br>
		邮箱&nbsp;:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="" id="mail" placeholder="接收新密码的邮箱"> <br>
		<input type="hidden" id="telphone">
		<input type="hidden" id="userId">
		<button onclick="resetPwd()">点击重置密码</button>

	</body>

	<script type="text/javascript" src="/js/plugins/jquery/jquery.min.js"></script>
	<script type="text/javascript" src="/js/plugins/jquery.easing/jquery.easing.min.js"></script>
	<script type="text/javascript" src="/js/plugins/sui/sui.min.js"></script>
	<script type="text/javascript" src="/js/plugins/jquery-placeholder/jquery.placeholder.min.js"></script>

	<script type="text/javascript">
		function getById(){
			var userName = $("#username").val()
			$.ajax({
				url: "/register/checkUserName",
				data:{userName:userName},
				dateType: "json",
				type: "post",
				async: true,
				success:function (result) {
					if (result.code == 200){
						var user = result.data
						if (user==null){
							alert("请输入正确的用户名!")
						}
						var telphone = user.phone;
						if (confirm('我们将向您的手机号:   '+user.phone.substring(0,3)+"********  发送一条验证码.请注意查收")){
							$("#telphone").val(user.phone)
							$("#userId").val(user.id)
							$.ajax({
								url: "/register/duanXin",
								data:{phone:telphone},
								dateType: "json",
								type: "post",
								async: true,
								success:function (data) {
								},
								error:function () {
									alert("系统异常")
								}
							})
						}
					}else{
						alert("系统繁忙")
					}

				},
				error:function () {
					alert("系统异常")
				}
			})
		}


		/* 判断验证码是否正确或超时 */
		function checkVerifyCode() {
			var telphone = $("#telphone").val()
			/*用户输入的验证码*/
			var verify = $("#verify").val()
			if (verify.length == 6 ) {
				$.ajax({
					url: "/register/getVerify",
					data: {telphone:telphone},
					dateType: "json",
					type: "post",
					async: true,
					success: function (result) {
						var data = result.data
						/*alert("用戶輸入的驗證碼為："+verify)
                   		 alert("系統生成的驗證碼為："+data)*/
						if (data != null) {
							if (verify == data) {
								$("#checkVerify").html("<span style='color: blue;font-size: 15px'>√</span>")
								$("#telphone").val(1)
							}else {
								$("#checkVerify").html('<span style="color: red">验证码不正确或者已经超时!</span><a href="javascript:void(0);">重新获取获取短信验证码</a>')
								return false;
							}
						}

					},
					error: function () {
						alert("系统异常")
					}
				})
			}

		}



		function resetPwd(){
			var userId = $("#userId").val()
			var code = $("#telphone").val();
			var mail = $("#mail").val()
			if (code == 1) {
				$.ajax({
					url: "/register/resetPwd",
					data: {userId:userId,mail:mail},
					dateType: "json",
					type: "post",
					async: true,
					success: function (result) {
						if (result.code == 200) {
							alert("新的密碼已經發送到您的郵箱，請您妥善保管！")
							location.href = "/login/toLogin"
						} else {
							alert("系统繁忙")
						}

					},
					error: function () {
						alert("系统异常")
					}
				})
			}else{
				alert("請輸入正確的驗證碼！")
			}

		}

	</script>
</html>